package dayong.com;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.Connection;

import conn.Connection1;

/**
 * Servlet implementation class UpdateServlet
 */
@WebServlet(description = "修改图片", urlPatterns = { "/UpdateServlet" })
public class UpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Connection1 conn =new Connection1();
		Connection connection = conn.getConnection();
		int id = Integer.parseInt(request.getParameter("id")); 
		String imgOtherName  = request.getParameter("imgOtherName"); 
		String sql = "update img set imgOtherName=? where id=?";
		// 获取PreparedStatement
		PreparedStatement ps;
		try {
			ps = connection.prepareStatement(sql);
			ps.setString(1, imgOtherName);
			ps.setInt(2, id);
			ps.executeUpdate();
			ps.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		response.sendRedirect("FindImgServlet");
		}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
